import 'package:little_painter/utils/logger_utils.dart';
import 'package:sqflite/sqflite.dart';

import '../entities/draw_contents.dart';

class DBUtils {
  static String dbName = 'little_painter.db';
  static int dbVersion = 1;
  static Database? db;

  static init() async {
    final open = db?.isOpen ?? false;
    if (!open) {
      db = await openDatabase(
        dbName,
        version: dbVersion,
        onCreate: (database, version) {
          database.execute(_createDrawContentTab());
        },
      );
    }
    LogUtils.d('DBUtils open:$open ; path:${db?.path}');
  }

  static String _createDrawContentTab() {
    return "CREATE TABLE '${DrawContent.columnTabName}' "
        "(${DrawContent.columnId} integer primary key autoincrement,"
        "${DrawContent.columnName} TEXT,"
        "${DrawContent.columnContent} TEXT,"
        "${DrawContent.columnTimestamp} TEXT,"
        "${DrawContent.columnDescription} TEXT)";
  }
}
